﻿//-----------------------------------------------------------------------
// <copyright file="EntityTupleTemplate.cs" company="tuliprules.org">
//     Copyright (c) 2010 tuplelister, tuliprules.org.
// </copyright>
// <summary>This is the EntityTupleTemplate class.</summary>
//-----------------------------------------------------------------------

namespace Tulip.Rules.CodeGen.Templates
{
    using System.Text;
    using CodeGen;
    using Models.ClosedWorld;

    /// <summary>
    /// A template for creating Entity Tuples.  This is a partial class that
    /// extends a T4 preprocessor template.
    /// </summary>
    public partial class EntityTupleTemplate : IModelTemplate
    {
        /// <summary>
        /// A class definition for the required entity tuple class.
        /// </summary>
        private ClassDef modelClassDef;

        /// <summary>
        /// Registers the GetGeneratedSource method with the code generator.
        /// </summary>
        /// <param name="generator">The code generator.</param>
        public void RegisterWithGenerator(Generator generator)
        {
            generator.RegisterTupleTypeGenerator(this.GetGeneratedSource);
        }

        /// <summary>
        /// Generates source code for the given class definition
        /// </summary>
        /// <param name="classDef">
        /// A class definition for the required entity tuple class.
        /// </param>
        /// <returns>
        /// Source code for the entity tuple class.
        /// </returns>
        public StringBuilder GetGeneratedSource(ClassDef classDef)
        {
            this.modelClassDef = classDef;
            this.TransformText();
            return this.GenerationEnvironment;
        }
    }
}
